<template>
  <div>

    <el-card class="box-card">
      <div>
        <el-form label-width="80px"
                 class="form-control">

          <el-form-item label="交易类型">
            <el-select v-model="queryData.dealType"
                       size="small"
                       placeholder="请选择">
              <el-option label="支出"
                         :value="1">
              </el-option>

              <el-option label="收入"
                         :value="2">
              </el-option>

            </el-select>
          </el-form-item>
          <el-form-item label="用户id">
            <el-input v-model="queryData.userId"
                      size="small"></el-input>
          </el-form-item>
          <el-form-item class="sercheItem"
                        label="用户名称">
            <!-- <el-input></el-input> -->

            <el-row type="flex"
                    :gutter="4"
                    align="middle">
              <el-col :span="1.5">

              </el-col>
              <el-col :span="10">
                <el-input v-model="queryData.realname"
                          size="small"></el-input>
              </el-col>
              <el-col :span="1.5">
                <el-button size="small"
                           type="primary"
                           icon="el-icon-search"
                           @click="search">搜索</el-button>
              </el-col>
              <el-col :span="1.5">
                <el-button icon='el-icon-refresh'
                           size="small"
                           @click="reset">重置</el-button>
              </el-col>
            </el-row>
          </el-form-item>
        </el-form>
      </div>
      <el-table :data="tableData"
                v-loading="loading"
                style="width: 100%"
                :header-cell-style="{background:'#f8f8f9','text-align':'center'}"
                :cell-style="{'text-align':'center'}">
        <el-table-column type="selection"
                         width="120">
        </el-table-column>
        <el-table-column prop="createTime"
                         label="创建时间">
        </el-table-column>
        <el-table-column prop="sum"
                         label="交易金额">
        </el-table-column>
        <el-table-column prop="money"
                         label="交易类型">
          <template slot-scope="scope">
            <span>{{scope.row.dealType==1?'支出':'收入'}}</span>
          </template>
        </el-table-column>

        <el-table-column prop="userId"
                         label="用户id">
        </el-table-column>
        <el-table-column prop="realName"
                         label="用户名称">
        </el-table-column>

      </el-table>
      <div class="page"
           v-show="total!=0">
        <el-pagination background
                       @size-change="handleSizeChange"
                       @current-change="handleCurrentChange"
                       :current-page="queryData.pageNum"
                       :page-sizes="[3, 5, 7, 9]"
                       :page-size="queryData.pageSize"
                       layout="total, sizes, prev, pager, next, jumper"
                       :total="total">
        </el-pagination>
      </div>
    </el-card>

  </div>
</template>

<script>
export default {
  data() {
    return {
      queryData: {
        pageNum: 1,
        pageSize: 5,
        dealType: null,
        userId: null,
        realName: null
      },
      loading: false,
      tableData: [],
      total: 0
    }
  },
  mounted() {
    this.getDate()
  },
  methods: {
    async getDate() {
      this.loading = true
      let { data } = await this.$axios.get('com/bill/list', { params: this.queryData })
      console.log(data)
      this.tableData = data.rows
      this.total = data.total
      this.loading = false
    },
    handleSizeChange(val) {
      this.queryData.pageSize = val
      this.getDate()
    },
    handleCurrentChange(val) {
      this.queryData.pageNum = val
      this.getDate()
    },
    search() {
      this.getDate()
    },
    reset() {
      this.queryData = {
        pageNum: 1,
        pageSize: 5,
        dealType: null,
        userId: null,
        realName: null
      }
    }
  }
}
</script>

<style lang="scss" scoped>
.form-control {
  display: flex;
  justify-content: space-around;
}
.page {
  margin-top: 15px;
  display: flex;
  justify-content: flex-end;
}
</style>